package HashTable;

public class _202_HAPPY_NUMBER {
    //hint:run divide loop until sum less than 10,and judge if the sum is 1 or 7,if that,return true,else return false;
    public boolean isHappy(int n) {
        int Sum = n;
        while (Sum > 9) {
            int tempSum = 0;
            int div = Sum;
            while (div != 0) {
                int res = div%10;
                tempSum+=res*res;
                div = div/10;
            }
            Sum = tempSum;
        }
        if (Sum == 1 || Sum == 7) {
            return true;
        } else {
            return false;
        }
    }
}
